﻿using CashFlow.Web;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting.Web;
using System.Web;
using System.Security.Principal;
using Should.Fluent;
using System.Web.Security;
using CashFlow.Web.Models;
using CashFlow.Entities;

namespace CashFlow.Web.Tests
{
		/// <summary>
		///This is a test class for MvcApplicationTest and is intended
		///to contain all MvcApplicationTest Unit Tests
		///</summary>
	[TestClass()]
	public class MvcApplicationTest
	{
		[TestMethod()]
		public void When_No_Auth_Cookie_Returns_Null_Principal()
		{
			var target = new MvcApplication_Accessor();
			HttpCookie cookie = null;

			var actual = target.GetPrincipal(cookie);

			actual.Should().Be.Null();
		}

		[TestMethod()]
		public void When_Auth_Cookie_Present_Returns_Principal_With_AppIdentity()
		{
			var target = new MvcApplication_Accessor();
			var authTicket = new FormsAuthenticationTicket(1, "", DateTime.Now, DateTime.Now.AddMinutes(30), false, "");
			var encTicket = FormsAuthentication.Encrypt(authTicket);
			var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
		
			var actual = target.GetPrincipal(cookie);

			actual.Should().Not.Be.Null();
			actual.Identity.Should().Be.OfType<AppIdentity>();
		}
	}
}
